package com.makefuture.controller;

import java.io.File;
import java.util.List;

import com.jfinal.core.Controller;
import com.jfinal.upload.UploadFile;

public class UploadController  extends Controller{

	public void index() {
		render("");
	}
	public void uploadFlie() {
		List<UploadFile> files = getFiles("/upload", 1024*1024*1024);
		for (UploadFile uploadFile : files) {
			 File f = uploadFile.getFile();
			 String name = getPara("name");
			 System.out.println(name);
			 System.out.println("rename:"+uploadFile.getUploadPath().substring(0,uploadFile.getUploadPath().length()-6)+System.currentTimeMillis()+uploadFile.getFileName());
			 f.renameTo(new File(uploadFile.getUploadPath().substring(0,uploadFile.getUploadPath().length()-6)+System.currentTimeMillis()+uploadFile.getFileName()));
			System.out.println(uploadFile.getFileName()+" "+uploadFile.getUploadPath());
			System.out.println(uploadFile.getContentType()+" "+uploadFile.getOriginalFileName()+" "+uploadFile.getFile());
			System.out.println();
			
			/**
			 *  UploadFile upFile = getFile();//单个上传文件一句搞定  默认路径是 upload
//          UploadFile upFile = getFile("FILE", filedir, maxSize, "utf-8");//只用于表单提交方式， 单个上传文件
            List<UploadFile> upFiles = getFiles(filedir, MAXSize, "utf-8");//批量上传文件
			 */
			
		}
	}
    /**
     *文件下载 
     */
	public void test2() {
        try {
            String pathname = this.getRequest().getServletContext().getRealPath("/") + "JFinal_Manual_1.5.pdf";
            System.out.println("pathname : " + pathname);
            renderFile(new File(pathname));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
